import { createStore } from 'vuex'
import user from './user';
import user1 from './user1';
import user2 from './user2';
import user3 from './user3'

export default createStore({

  state: {
    num: 0,
    dzlist: []
  },

  mutations: {
    setNum(state) {
      state.num++
    },
    setNum2(state, val) {
      state.num += val
    },
    setDzlist(state, arr) {
      state.dzlist = arr;
    }
  },

  getters: {
    totalPrice(state) {
      return state.num * 100
    }
  },

  actions: {
    getDZ(context) {
      context.commit('setDzlist', [1, 2, 3]);
      const api = 'https://api.apiopen.top/getJoke?page=1&count=5&type=text';
      // axios.get(api).then((result) => { store.setDZlist(result.data.result) });
      fetch(api).then((res) => res.json()).then(result => {
        console.log(result);
        context.commit('setDzlist', result.result);
      });
    }
  },

  modules: {
    user,
    user1,
    user2,
    user3
  }
})
